<%@ page import="com.Bean.Message" %>
<%@ page import="com.Bean.Ticket" %>
<%@ page import="com.Bean.User" %>
<%@ page import="com.Util.DB" %>
<%@ page import="com.Util.MessDao" %>
<%@ page import="com.Util.TkDao" %>
<%@ page import="java.util.Set" %>
<%@ page import="com.Util.UserDao" %>
<%--
  Created by IntelliJ IDEA.
  User: SZB
  Date: 2019/6/25
  Time: 13:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    boolean istest = DB.jsptest;

    String tkid = new String();
    String username = new String();
    User user = new User();

    if (istest) {
        username = request.getParameter("u");
        tkid = request.getParameter("tkid");

    } else if (session.getAttribute("username") == null) {

        response.sendRedirect("../login.jsp");
        //request.getRequestDispatcher("../login.jsp").forward(request, response);
    } else {
        username = session.getAttribute("username").toString();
        if (request.getParameter("tkid") == null) {
            tkid = session.getAttribute("tkid").toString();
        } else {
            tkid = request.getParameter("tkid");
        }

    }
    Ticket tk = TkDao.selectTkbyId(tkid);
    user = UserDao.getUser(username);
%>
<html>
<head>
    <title>咨询信息</title>
    <link rel="stylesheet" href="../css/services.css">
    <script src="../js/scripts.minf5b501.js"></script>
</head>
<body>
<section id="header">
    <div class="container">
        <ul class="top-nav">
            <li class="primary-action">
                <a href="../logout" class="btn">
                    注销
                </a>
            </li>
        </ul>
    </div>
</section>
<section>
    <nav id="nav" class="navbar navbar-default navbar-main" role="navigation">
        <div class="container">

            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#primary-nav">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>

            <div class="collapse navbar-collapse" id="primary-nav">
                <ul class="nav navbar-nav">
                    <li menuitemname="Home" class="" id="Primary_Navbar-Home">
                        <a href="../index.html">
                            主页
                        </a>
                    </li>

                    <li menuitemname="Services" class="dropdown" id="Primary_Navbar-Services">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            服务
                            &nbsp;<b class="caret"></b> </a>
                        <ul class="dropdown-menu">
                            <li menuitemname="pm-addon-overview" id="Primary_Navbar-Services-pm-addon-overview">
                                <a href="./myvps.jsp">
                                    我的vps
                                </a>
                            </li>
                            <li menuitemname="My Services" id="Primary_Navbar-Services-My_Services">
                                <a href="./tickets.jsp">
                                    服务咨询
                                </a>
                            </li>
                            <li menuitemname="My Services">
                                <a href="./openticket.jsp">
                                    咨询客服
                                </a>
                            </li>

                        </ul>
                    </li>

                    <li menuitemname="Home" class="" id="Primary_Navbar-Home">
                        <a href="./ordervps.jsp">
                            购买VPS
                        </a>
                    </li>

                </ul>
            </div>
        </div>
    </nav>
</section>
<section id="main-body">

    <div class="container">
        <div class="row">
            <div class="col-md-9 pull-md-right">

                <div class="header-lined">
                    <h1>查看问题</h1>
                    <ol class="breadcrumb">
                        <li>
                            <a href="index.php"> 主页
                            </a></li>
                        <li>
                            <a href="./tickets.jsp">查看问题
                            </a></li>
                        <li class="active">
                            <%=tk.getId()%>
                        </li>
                    </ol>
                </div>

            </div>
            <div class="col-md-3 pull-md-left sidebar">
                <div menuitemname="Client Details" class="panel panel-sidebar panel-sidebar">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <i class="fas fa-user"></i>&nbsp; 我的信息
                            <i class="fas fa-chevron-up panel-minimise pull-right"></i>
                        </h3>
                    </div>

                    <div class="panel-body">
                        <strong><%=user.getUsername()%></strong><br>
                        <%=user.getEmail()%><br>
                        <%=user.getFamilyname()%> <%=user.getName()%><br>
                    </div>
                    <div class="panel-footer clearfix">

                    </div>
                </div>
            </div>
            <div class="col-md-9 pull-md-right main-content">
                <div class="panel panel-info">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            Ticket Information
                        </h3>
                    </div>
                    <div class="panel-body container-fluid">
                        <div class="row">
                            <div class="col-md-2 col-xs-6">
                                <b>ID</b><br><%=tk.getId()%>
                            </div>
                            <div class="col-md-4 col-xs-6">
                                <b>问题</b><br><%=tk.getSubject()%>
                            </div>
                            <div class="col-md-4 col-xs-6">
                                <b>状态</b><br><%=tk.getStatus()%>
                            </div>
                            <%
                                if (tk.getStatus().equals("open")) {
                            %>
                            <form method="get" action="../closeticket">
                            <div class="col-xs-6 col-md-2">
                                <input type="hidden" name="tkid" value="<%=tkid%>">
                                <input type="hidden" name="username" value="<%=username%>">
                                <input class="btn btn-primary" type="submit" name="save" value="关闭">
                            </div>
                            </form>
                            <%
                                }
                            %>

                        </div>
                    </div>
                </div>
                <%
                    if (tk.getStatus().equals("closed")) {
                %>
                <div class="alert alert-warning text-center">
                    这个提问已经关闭，你可以重新回复来恢复提问
                </div>
                <%
                    }
                %>
                <div class="panel panel-info panel-collapsable panel-collapsed hidden-print">
                    <div class="panel-heading" id="ticketReply">
                        <div class="collapse-icon pull-right">

                        </div>
                        <h3 class="panel-title">
                            &nbsp; 回复
                        </h3>
                    </div>
                    <div class="panel-body panel-body-collapsed">
                        <form method="get" action="../addmessage"
                              enctype="multipart/form-data" role="form" id="frmReply">
                            <input type="hidden" name="tkid" value="<%=tkid%>">
                            <input type="hidden" name="username" value="<%=username%>">
                            <div class="row">
                                <div class="form-group col-sm-4">
                                    <label for="inputName">Name</label>
                                    <input class="form-control disabled" type="text" id="inputName"
                                           value="<%=username%>"
                                           disabled="disabled"></div>
                                <div class="form-group col-sm-5">
                                    <label for="inputEmail">Email Address</label>
                                    <input class="form-control disabled" type="text" id="inputEmail"
                                           value="<%=user.getEmail()%>" disabled="disabled"></div>
                            </div>
                            <div class="form-group">
                                <label for="inputMessage">Message</label>
                                <div class="md-editor" id="1561561754079">
                                    <textarea name="content" id="inputMessage" rows="12"
                                              class="form-control markdown-editor md-input"
                                              data-auto-save-name="client_ticket_reply_739417"
                                              style="resize: vertical;"></textarea>
                                    <div class="md-fullscreen-controls"><a href="#" class="exit-fullscreen"
                                                                           title="Exit fullscreen"><span
                                            class="glyphicon glyphicon-fullscreen"></span></a></div>
                                </div>
                            </div>
                            <div class="form-group text-center">
                                <input class="btn btn-primary" type="submit" name="save" value="Submit">
                                <input class="btn btn-default" type="reset" value="Cancel"
                                       onclick="jQuery('#ticketReply').click()">
                            </div>
                        </form>
                    </div>
                </div>
                <%
                    Set<Message> messSet = MessDao.selectMessBytkid(request.getParameter("tkid"));
                    for (Message mess : messSet) {
                %>

                <div class="ticket-reply markdown-content">
                    <div class="date">
                        <%=mess.getPosttime()%>
                    </div>

                    <div class="user" style="padding-left: 10px;">

                        <span class="name">
                        <%=mess.getUsername()%>
                        </span>
                        <span class="type">
                        <%
                            if(user.getStaff().equals("staff"))
                            {
                        %>
                            客服
                            <%
                            }else{
                            %>
                            客户
                            <%
                                }
                            %>
                        </span>
                    </div>
                    <div class="message">
                        <p><%=mess.getContent()%>
                        </p>
                    </div>
                </div>
                <%
                    }
                %>


            </div>
            <div>


            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</section>
</body>
</html>
